<?php
include_once( "common.php" );
checkLogin( STATUS_ADMIN );

# Verify the user
if ( ! isValidEntry( "User", $_GET["id"] ) )
    outputAlert( "Invalid input", "You have entered invalid input." );

outputHeader();

# Fetch information about the user
$result_user = db_query( "SELECT * FROM User WHERE id = {$_GET["id"]}" );
$row_user = db_fetch_object( $result_user );

print <<<EOF
<div class = "header">Edit user</div>
<form action = "editUser.php" method = "post">
<input type = "hidden" name = "id" value = "{$_GET["id"]}" />
<table style = "width:600px;">
<tr>
<td>User</td><td><input type = "text" name = "user" value = "{$row_user->name}" /></td>
</tr>
<tr>
<td>Password</td><td><input type = "password" name = "password" /></td>
<td>Confirm</td><td><input type = "password" name = "confirm" /></td>
</tr>
<tr>
<td>Status</td>
<td><select name = "status">

EOF;

# Output status information
print "<option value = '" . STATUS_GUEST . "'" . ( $row_user->status == STATUS_GUEST ? " selected = 'selected'" : "" ) . ">Guest</option>\n";
print "<option value = '" . STATUS_USER . "'" . ( $row_user->status == STATUS_USER ? " selected = 'selected'" : "" ) . ">User</option>\n";
print "<option value = '" . STATUS_ADMIN . "'" . ( $row_user->status == STATUS_ADMIN ? " selected = 'selected'" : "" ) . ">Admin</option>\n";

print <<<EOF
</select></td>
</tr>
<tr>
<td>Visibility</td><td>

EOF;

# Output visibility information
$result = db_query( "SELECT * FROM Project ORDER BY name" );
while ( $row = db_fetch_object( $result ) )
{
    if ( db_num_rows( db_query( "SELECT * FROM UserProject WHERE user = {$_GET["id"]} AND project = {$row->id}" ) ) == 0 )
        print "<input type = 'checkbox' name = 'visibility[]' value = '{$row->id}' />{$row->name}<br />\n";
    else
        print "<input type = 'checkbox' name = 'visibility[]' value = '{$row->id}' checked = 'checked' />{$row->name}<br />\n";
}

print <<<EOF
</td></tr>
<tr><td>Locked</td><td>

EOF;

# Output locked information
if ( $row_user->locked == 0 )
    print "<input type = 'checkbox' name = 'lock' value = 'lock' />\n";
else
    print "<input type = 'checkbox' name = 'lock' value = 'lock' checked = 'checked' />\n";

print <<<EOF
</td></tr>
<tr>
<td>Feed</td><td>{$row_user->feed}</td>
<td></td><td><input type = "checkbox" name = "feed" value = "feed" />Reset feed hash</td>
</tr>
<tr>
<td>Delete</td><td><input type = "checkbox" name = "delete[]" value = "delete" />Delete user</td>
<td></td><td><input type = "checkbox" name = "delete[]" value = "confirm" />Confirm deletion</td>
</tr>
<tr><td></td><td><input type = "submit" value = "Update user" /></td></tr>
</table>
</form>

EOF;

outputFooter();
?>
